/*
******************************************************************************************************* 
**  Copyright (C) 2019, 苏州检易生物科技有限公司 
**  All rights reserved. 
** 
**  FileName:       	protocol_stack.h
**  Description:	
**  Author:        	 
**  Version				v0.1
**  Date:           	2019-06-29
**	Function List： 
**  History:         
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*                                              	防止重复包含
*********************************************************************************************************
*/

#ifndef _TCP_PROTOCOL_H_
#define _TCP_PROTOCOL_H_
/*
*********************************************************************************************************
*                                              	调试开关
*********************************************************************************************************
*/



/*
*********************************************************************************************************
*                                              	头文件
*********************************************************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stm32h7xx_hal.h"
#include "eth_task.h"
#include "log_console.h"
/*
*********************************************************************************************************
*                                              	宏定义
*********************************************************************************************************
*/

//#define		PROTOCOL_SIZE_MAX	(3072)

//#define 	PROTOCOL_DATA_LEN(x)		((x)-sizeof(protocol_head_t)-1)
/*
*********************************************************************************************************
*                                              枚举和结构体类型定义
*********************************************************************************************************
*/
typedef enum{
	CMD_HOME	= 0x00,
	CMD_JOG		= 0x01,
	CMD_CLAW	= 0x02,
	CMD_CLAW_STATUS = 0x03,	
	CMD_SCAN = 0x04,
	CMD_RFID = 0x05,
	CMD_RFID_WRITE = 0x0C,
	
	CMD_PUMP = 0x06,
	CMD_VALVE = 0x07,
	CMD_SURFACE = 0x08,
	
	CMD_SUCK = 0x09,
	CMD_RESET_TIP = 0x0A,
	CMD_LED = 0x0B,
	
	CMD_MOTOR_DISABLE	 = 0x0E,
	CMD_QURY_ENC			= 0x0F,
	
	
	RPLY_HOME	= 0x10,
	RPLY_JOG	= 0x11,
	RPLY_CLAW	= 0x12,
	RPLY_CLAW_STATUS = 0x13,
	RPLY_SCAN = 0x14,
	RPLY_RFID = 0x15,
	RPLY_TEMP = 0x16,
	RPLY_SURFACE = 0x18,
	
	RPLY_SUCK = 0x19,
	RPLY_RESET_TIP = 0x1A,
	RPLY_ID = 0x1B,
	RPLY_BTN = 0x1C,
	RPLY_RFID_WRITE = 0x1D,
	RELY_QURY_ENC = 0x1F
	
}protocol_cmd_t;
typedef struct{
	int16_t react_temp;
	int16_t reagent_temp;
	int16_t reagent_bk_temp;
	int16_t clean_temp;
	uint8_t  sys_status;
}period_upload_t;
#pragma pack()

typedef void (*pfn_handler_callback)(protocol_cmd_t cmd,uint8_t * buff,uint16_t size);

typedef struct PROTOCOL_HANDLER_NODE_T
{
	protocol_cmd_t cmd;
	pfn_handler_callback pfn_handler;
	struct PROTOCOL_HANDLER_NODE_T * p_next;
}protocol_handler_node_t;
/*
*********************************************************************************************************
*                                              	全局变量声明
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*                                              	函数声明
*********************************************************************************************************
*/
void protocol_init(void);

protocol_handler_node_t* protocol_handler_register(protocol_cmd_t cmd,pfn_handler_callback);

//void protocol_upload(protocol_cmd_t cmd,uint8_t* data,uint16_t size);
void protocol_input(protocol_cmd_t cmd,uint8_t* buff,uint16_t size);
//protocol_err_t upld_barcode(uint8_t* rack,uint16_t pos,uint8_t* barcode,uint16_t barcode_size);
//void upld_supply_consume(uint16_t supply_type);
uint16_t endian_short(uint16_t arg);
uint32_t endian_int(uint32_t arg);
#endif
